{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fc0a1baa",
   "metadata": {},
   "source": [
    "## numpy函数的讲解-一元函数\n",
    "\n",
    "numpy函数分为一元函数、二元函数和聚合函数。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3352f0d8",
   "metadata": {},
   "source": [
    "1. 一元函数:使用时不需要传递其他参数，只需要传递数组即可完成。\n",
    "\n",
    "一元函数主要有：\n",
    "np.abs,np.sqrt,np.square"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3d066fb2",
   "metadata": {},
   "source": [
    "| 序号 ||  函数   | 描述  |\n",
    "|  :----  ||  :----  | ----:  |\n",
    "| 01 || np.abs  | 求绝对值 |\n",
    "| 02 || np.sqrt | 开方 |\n",
    "| 03 || np.square | 平方 |\n",
    "| 04 || np.exp | 计算指数 |\n",
    "| 05 || np.ceil | 向正无穷大的方向取整，比如将5.1变成6，-6.3变成-6 |\n",
    "| 06 || np.sign | 将数组中的值标签化：大于0变成1，小于0变成-1，等于0变成0 |\n",
    "| 07 || np.floor | 向负无穷大取整，比如将5.1变成5，-6.3变成-7 |\n",
    "| 08 || np.rint/np.round | 四舍五入 |\n",
    "| 09 || np.modf | 返回数据的两个部分，一个部分是整数，一个部分是小数 |\n",
    "| 10 || np.isnan | 判断数据是否为数值 |\n",
    "| 11 || np.isinf | 判断数据是否是inf |\n",
    "| 12 || np.sin// | 三角函数和反三角函数 |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "91b9cec0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2ead12c3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-3.22050533, -8.04219048,  0.12791285, -7.45827309,  8.53866665],\n",
       "       [ 9.22183721, -6.94738275, -4.52490957, -0.35545867,  6.29462803],\n",
       "       [-2.6525515 ,  9.39652661, -3.02203525,  9.99882355, -1.48034756]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#random.uniform一种平均分布函数，有正有负数\n",
    "data = np.random.uniform(-10,10,size=(3,5))\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b73be416",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3.22050533, 8.04219048, 0.12791285, 7.45827309, 8.53866665],\n",
       "       [9.22183721, 6.94738275, 4.52490957, 0.35545867, 6.29462803],\n",
       "       [2.6525515 , 9.39652661, 3.02203525, 9.99882355, 1.48034756]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1.abs求绝对值函数。此函数不改变原函数\n",
    "np.abs(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "4bef8210",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [3, 4, 5]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2 = np.arange(6).reshape(2,3)\n",
    "data2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "3b4f573a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1 2]\n",
      " [3 4 5]]\n",
      "********************\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[0.        , 1.        , 1.41421356],\n",
       "       [1.73205081, 2.        , 2.23606798]])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2.针对每个数开平方np.sqrt()\n",
    "print(data2)\n",
    "print('*'*20)\n",
    "np.sqrt(data2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "9620a898",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1 2]\n",
      " [3 4 5]]\n",
      "********************\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  4],\n",
       "       [ 9, 16, 25]])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3.对数组中的每个数平方np.square()\n",
    "print(data2)\n",
    "print('*'*20)\n",
    "np.square(data2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "8da82369",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-3.22050533 -8.04219048  0.12791285 -7.45827309  8.53866665]\n",
      " [ 9.22183721 -6.94738275 -4.52490957 -0.35545867  6.29462803]\n",
      " [-2.6525515   9.39652661 -3.02203525  9.99882355 -1.48034756]]\n",
      "********************\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[-1., -1.,  1., -1.,  1.],\n",
       "       [ 1., -1., -1., -1.,  1.],\n",
       "       [-1.,  1., -1.,  1., -1.]])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4.数据归类函数np.sign()\n",
    "print(data)\n",
    "print('*'*20)\n",
    "np.sign(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "7ec9fac5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-3.22050533 -8.04219048  0.12791285 -7.45827309  8.53866665]\n",
      " [ 9.22183721 -6.94738275 -4.52490957 -0.35545867  6.29462803]\n",
      " [-2.6525515   9.39652661 -3.02203525  9.99882355 -1.48034756]]\n",
      "********************\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[-3., -8.,  1., -7.,  9.],\n",
       "       [10., -6., -4., -0.,  7.],\n",
       "       [-2., 10., -3., 10., -1.]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 5.正向取证np.ceil()\n",
    "print(data)\n",
    "print('*'*20)\n",
    "np.ceil(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "be1369ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-4., -9.,  0., -8.,  8.],\n",
       "       [ 9., -7., -5., -1.,  6.],\n",
       "       [-3.,  9., -4.,  9., -2.]])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 6.向下取整np.floor()\n",
    "np.floor(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "a1844724",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-3.22050533 -8.04219048  0.12791285 -7.45827309  8.53866665]\n",
      " [ 9.22183721 -6.94738275 -4.52490957 -0.35545867  6.29462803]\n",
      " [-2.6525515   9.39652661 -3.02203525  9.99882355 -1.48034756]]\n",
      "********************\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[-3., -8.,  0., -7.,  9.],\n",
       "       [ 9., -7., -5., -0.,  6.],\n",
       "       [-3.,  9., -3., 10., -1.]])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 7.四舍五入np.rint()/np.round()\n",
    "print(data)\n",
    "print('*'*20)\n",
    "np.rint(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "d49f041b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([[-0.22050533, -0.04219048,  0.12791285, -0.45827309,  0.53866665],\n",
       "        [ 0.22183721, -0.94738275, -0.52490957, -0.35545867,  0.29462803],\n",
       "        [-0.6525515 ,  0.39652661, -0.02203525,  0.99882355, -0.48034756]]),\n",
       " array([[-3., -8.,  0., -7.,  8.],\n",
       "        [ 9., -6., -4., -0.,  6.],\n",
       "        [-2.,  9., -3.,  9., -1.]]))"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 8.返回数据的整数和小数部分np.modf()，结果是两个数组\n",
    "np.modf(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a0dbe62e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on ufunc object:\n",
      "\n",
      "sqrt = class ufunc(builtins.object)\n",
      " |  Functions that operate element by element on whole arrays.\n",
      " |  \n",
      " |  To see the documentation for a specific ufunc, use `info`.  For\n",
      " |  example, ``np.info(np.sin)``.  Because ufuncs are written in C\n",
      " |  (for speed) and linked into Python with NumPy's ufunc facility,\n",
      " |  Python's help() function finds this page whenever help() is called\n",
      " |  on a ufunc.\n",
      " |  \n",
      " |  A detailed explanation of ufuncs can be found in the docs for :ref:`ufuncs`.\n",
      " |  \n",
      " |  **Calling ufuncs:** ``op(*x[, out], where=True, **kwargs)``\n",
      " |  \n",
      " |  Apply `op` to the arguments `*x` elementwise, broadcasting the arguments.\n",
      " |  \n",
      " |  The broadcasting rules are:\n",
      " |  \n",
      " |  * Dimensions of length 1 may be prepended to either array.\n",
      " |  * Arrays may be repeated along dimensions of length 1.\n",
      " |  \n",
      " |  Parameters\n",
      " |  ----------\n",
      " |  *x : array_like\n",
      " |      Input arrays.\n",
      " |  out : ndarray, None, or tuple of ndarray and None, optional\n",
      " |      Alternate array object(s) in which to put the result; if provided, it\n",
      " |      must have a shape that the inputs broadcast to. A tuple of arrays\n",
      " |      (possible only as a keyword argument) must have length equal to the\n",
      " |      number of outputs; use None for uninitialized outputs to be\n",
      " |      allocated by the ufunc.\n",
      " |  where : array_like, optional\n",
      " |      This condition is broadcast over the input. At locations where the\n",
      " |      condition is True, the `out` array will be set to the ufunc result.\n",
      " |      Elsewhere, the `out` array will retain its original value.\n",
      " |      Note that if an uninitialized `out` array is created via the default\n",
      " |      ``out=None``, locations within it where the condition is False will\n",
      " |      remain uninitialized.\n",
      " |  **kwargs\n",
      " |      For other keyword-only arguments, see the :ref:`ufunc docs <ufuncs.kwargs>`.\n",
      " |  \n",
      " |  Returns\n",
      " |  -------\n",
      " |  r : ndarray or tuple of ndarray\n",
      " |      `r` will have the shape that the arrays in `x` broadcast to; if `out` is\n",
      " |      provided, it will be returned. If not, `r` will be allocated and\n",
      " |      may contain uninitialized values. If the function has more than one\n",
      " |      output, then the result will be a tuple of arrays.\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __call__(self, /, *args, **kwargs)\n",
      " |      Call self as a function.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  __str__(self, /)\n",
      " |      Return str(self).\n",
      " |  \n",
      " |  accumulate(...)\n",
      " |      accumulate(array, axis=0, dtype=None, out=None)\n",
      " |      \n",
      " |      Accumulate the result of applying the operator to all elements.\n",
      " |      \n",
      " |      For a one-dimensional array, accumulate produces results equivalent to::\n",
      " |      \n",
      " |        r = np.empty(len(A))\n",
      " |        t = op.identity        # op = the ufunc being applied to A's  elements\n",
      " |        for i in range(len(A)):\n",
      " |            t = op(t, A[i])\n",
      " |            r[i] = t\n",
      " |        return r\n",
      " |      \n",
      " |      For example, add.accumulate() is equivalent to np.cumsum().\n",
      " |      \n",
      " |      For a multi-dimensional array, accumulate is applied along only one\n",
      " |      axis (axis zero by default; see Examples below) so repeated use is\n",
      " |      necessary if one wants to accumulate over multiple axes.\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      array : array_like\n",
      " |          The array to act on.\n",
      " |      axis : int, optional\n",
      " |          The axis along which to apply the accumulation; default is zero.\n",
      " |      dtype : data-type code, optional\n",
      " |          The data-type used to represent the intermediate results. Defaults\n",
      " |          to the data-type of the output array if such is provided, or the\n",
      " |          the data-type of the input array if no output array is provided.\n",
      " |      out : ndarray, None, or tuple of ndarray and None, optional\n",
      " |          A location into which the result is stored. If not provided or None,\n",
      " |          a freshly-allocated array is returned. For consistency with\n",
      " |          ``ufunc.__call__``, if given as a keyword, this may be wrapped in a\n",
      " |          1-element tuple.\n",
      " |      \n",
      " |          .. versionchanged:: 1.13.0\n",
      " |             Tuples are allowed for keyword argument.\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      r : ndarray\n",
      " |          The accumulated values. If `out` was supplied, `r` is a reference to\n",
      " |          `out`.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      1-D array examples:\n",
      " |      \n",
      " |      >>> np.add.accumulate([2, 3, 5])\n",
      " |      array([ 2,  5, 10])\n",
      " |      >>> np.multiply.accumulate([2, 3, 5])\n",
      " |      array([ 2,  6, 30])\n",
      " |      \n",
      " |      2-D array examples:\n",
      " |      \n",
      " |      >>> I = np.eye(2)\n",
      " |      >>> I\n",
      " |      array([[1.,  0.],\n",
      " |             [0.,  1.]])\n",
      " |      \n",
      " |      Accumulate along axis 0 (rows), down columns:\n",
      " |      \n",
      " |      >>> np.add.accumulate(I, 0)\n",
      " |      array([[1.,  0.],\n",
      " |             [1.,  1.]])\n",
      " |      >>> np.add.accumulate(I) # no axis specified = axis zero\n",
      " |      array([[1.,  0.],\n",
      " |             [1.,  1.]])\n",
      " |      \n",
      " |      Accumulate along axis 1 (columns), through rows:\n",
      " |      \n",
      " |      >>> np.add.accumulate(I, 1)\n",
      " |      array([[1.,  1.],\n",
      " |             [0.,  1.]])\n",
      " |  \n",
      " |  at(...)\n",
      " |      at(a, indices, b=None, /)\n",
      " |      \n",
      " |      Performs unbuffered in place operation on operand 'a' for elements\n",
      " |      specified by 'indices'. For addition ufunc, this method is equivalent to\n",
      " |      ``a[indices] += b``, except that results are accumulated for elements that\n",
      " |      are indexed more than once. For example, ``a[[0,0]] += 1`` will only\n",
      " |      increment the first element once because of buffering, whereas\n",
      " |      ``add.at(a, [0,0], 1)`` will increment the first element twice.\n",
      " |      \n",
      " |      .. versionadded:: 1.8.0\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      a : array_like\n",
      " |          The array to perform in place operation on.\n",
      " |      indices : array_like or tuple\n",
      " |          Array like index object or slice object for indexing into first\n",
      " |          operand. If first operand has multiple dimensions, indices can be a\n",
      " |          tuple of array like index objects or slice objects.\n",
      " |      b : array_like\n",
      " |          Second operand for ufuncs requiring two operands. Operand must be\n",
      " |          broadcastable over first operand after indexing or slicing.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      Set items 0 and 1 to their negative values:\n",
      " |      \n",
      " |      >>> a = np.array([1, 2, 3, 4])\n",
      " |      >>> np.negative.at(a, [0, 1])\n",
      " |      >>> a\n",
      " |      array([-1, -2,  3,  4])\n",
      " |      \n",
      " |      Increment items 0 and 1, and increment item 2 twice:\n",
      " |      \n",
      " |      >>> a = np.array([1, 2, 3, 4])\n",
      " |      >>> np.add.at(a, [0, 1, 2, 2], 1)\n",
      " |      >>> a\n",
      " |      array([2, 3, 5, 4])\n",
      " |      \n",
      " |      Add items 0 and 1 in first array to second array,\n",
      " |      and store results in first array:\n",
      " |      \n",
      " |      >>> a = np.array([1, 2, 3, 4])\n",
      " |      >>> b = np.array([1, 2])\n",
      " |      >>> np.add.at(a, [0, 1], b)\n",
      " |      >>> a\n",
      " |      array([2, 4, 3, 4])\n",
      " |  \n",
      " |  outer(...)\n",
      " |      outer(A, B, /, **kwargs)\n",
      " |      \n",
      " |      Apply the ufunc `op` to all pairs (a, b) with a in `A` and b in `B`.\n",
      " |      \n",
      " |      Let ``M = A.ndim``, ``N = B.ndim``. Then the result, `C`, of\n",
      " |      ``op.outer(A, B)`` is an array of dimension M + N such that:\n",
      " |      \n",
      " |      .. math:: C[i_0, ..., i_{M-1}, j_0, ..., j_{N-1}] =\n",
      " |         op(A[i_0, ..., i_{M-1}], B[j_0, ..., j_{N-1}])\n",
      " |      \n",
      " |      For `A` and `B` one-dimensional, this is equivalent to::\n",
      " |      \n",
      " |        r = empty(len(A),len(B))\n",
      " |        for i in range(len(A)):\n",
      " |            for j in range(len(B)):\n",
      " |                r[i,j] = op(A[i], B[j])  # op = ufunc in question\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      A : array_like\n",
      " |          First array\n",
      " |      B : array_like\n",
      " |          Second array\n",
      " |      kwargs : any\n",
      " |          Arguments to pass on to the ufunc. Typically `dtype` or `out`.\n",
      " |          See `ufunc` for a comprehensive overview of all available arguments.\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      r : ndarray\n",
      " |          Output array\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.outer : A less powerful version of ``np.multiply.outer``\n",
      " |                    that `ravel`\\ s all inputs to 1D. This exists\n",
      " |                    primarily for compatibility with old code.\n",
      " |      \n",
      " |      tensordot : ``np.tensordot(a, b, axes=((), ()))`` and\n",
      " |                  ``np.multiply.outer(a, b)`` behave same for all\n",
      " |                  dimensions of a and b.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> np.multiply.outer([1, 2, 3], [4, 5, 6])\n",
      " |      array([[ 4,  5,  6],\n",
      " |             [ 8, 10, 12],\n",
      " |             [12, 15, 18]])\n",
      " |      \n",
      " |      A multi-dimensional example:\n",
      " |      \n",
      " |      >>> A = np.array([[1, 2, 3], [4, 5, 6]])\n",
      " |      >>> A.shape\n",
      " |      (2, 3)\n",
      " |      >>> B = np.array([[1, 2, 3, 4]])\n",
      " |      >>> B.shape\n",
      " |      (1, 4)\n",
      " |      >>> C = np.multiply.outer(A, B)\n",
      " |      >>> C.shape; C\n",
      " |      (2, 3, 1, 4)\n",
      " |      array([[[[ 1,  2,  3,  4]],\n",
      " |              [[ 2,  4,  6,  8]],\n",
      " |              [[ 3,  6,  9, 12]]],\n",
      " |             [[[ 4,  8, 12, 16]],\n",
      " |              [[ 5, 10, 15, 20]],\n",
      " |              [[ 6, 12, 18, 24]]]])\n",
      " |  \n",
      " |  reduce(...)\n",
      " |      reduce(array, axis=0, dtype=None, out=None, keepdims=False, initial=<no value>, where=True)\n",
      " |      \n",
      " |      Reduces `array`'s dimension by one, by applying ufunc along one axis.\n",
      " |      \n",
      " |      Let :math:`array.shape = (N_0, ..., N_i, ..., N_{M-1})`.  Then\n",
      " |      :math:`ufunc.reduce(array, axis=i)[k_0, ..,k_{i-1}, k_{i+1}, .., k_{M-1}]` =\n",
      " |      the result of iterating `j` over :math:`range(N_i)`, cumulatively applying\n",
      " |      ufunc to each :math:`array[k_0, ..,k_{i-1}, j, k_{i+1}, .., k_{M-1}]`.\n",
      " |      For a one-dimensional array, reduce produces results equivalent to:\n",
      " |      ::\n",
      " |      \n",
      " |       r = op.identity # op = ufunc\n",
      " |       for i in range(len(A)):\n",
      " |         r = op(r, A[i])\n",
      " |       return r\n",
      " |      \n",
      " |      For example, add.reduce() is equivalent to sum().\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      array : array_like\n",
      " |          The array to act on.\n",
      " |      axis : None or int or tuple of ints, optional\n",
      " |          Axis or axes along which a reduction is performed.\n",
      " |          The default (`axis` = 0) is perform a reduction over the first\n",
      " |          dimension of the input array. `axis` may be negative, in\n",
      " |          which case it counts from the last to the first axis.\n",
      " |      \n",
      " |          .. versionadded:: 1.7.0\n",
      " |      \n",
      " |          If this is None, a reduction is performed over all the axes.\n",
      " |          If this is a tuple of ints, a reduction is performed on multiple\n",
      " |          axes, instead of a single axis or all the axes as before.\n",
      " |      \n",
      " |          For operations which are either not commutative or not associative,\n",
      " |          doing a reduction over multiple axes is not well-defined. The\n",
      " |          ufuncs do not currently raise an exception in this case, but will\n",
      " |          likely do so in the future.\n",
      " |      dtype : data-type code, optional\n",
      " |          The type used to represent the intermediate results. Defaults\n",
      " |          to the data-type of the output array if this is provided, or\n",
      " |          the data-type of the input array if no output array is provided.\n",
      " |      out : ndarray, None, or tuple of ndarray and None, optional\n",
      " |          A location into which the result is stored. If not provided or None,\n",
      " |          a freshly-allocated array is returned. For consistency with\n",
      " |          ``ufunc.__call__``, if given as a keyword, this may be wrapped in a\n",
      " |          1-element tuple.\n",
      " |      \n",
      " |          .. versionchanged:: 1.13.0\n",
      " |             Tuples are allowed for keyword argument.\n",
      " |      keepdims : bool, optional\n",
      " |          If this is set to True, the axes which are reduced are left\n",
      " |          in the result as dimensions with size one. With this option,\n",
      " |          the result will broadcast correctly against the original `array`.\n",
      " |      \n",
      " |          .. versionadded:: 1.7.0\n",
      " |      initial : scalar, optional\n",
      " |          The value with which to start the reduction.\n",
      " |          If the ufunc has no identity or the dtype is object, this defaults\n",
      " |          to None - otherwise it defaults to ufunc.identity.\n",
      " |          If ``None`` is given, the first element of the reduction is used,\n",
      " |          and an error is thrown if the reduction is empty.\n",
      " |      \n",
      " |          .. versionadded:: 1.15.0\n",
      " |      \n",
      " |      where : array_like of bool, optional\n",
      " |          A boolean array which is broadcasted to match the dimensions\n",
      " |          of `array`, and selects elements to include in the reduction. Note\n",
      " |          that for ufuncs like ``minimum`` that do not have an identity\n",
      " |          defined, one has to pass in also ``initial``.\n",
      " |      \n",
      " |          .. versionadded:: 1.17.0\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      r : ndarray\n",
      " |          The reduced array. If `out` was supplied, `r` is a reference to it.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> np.multiply.reduce([2,3,5])\n",
      " |      30\n",
      " |      \n",
      " |      A multi-dimensional array example:\n",
      " |      \n",
      " |      >>> X = np.arange(8).reshape((2,2,2))\n",
      " |      >>> X\n",
      " |      array([[[0, 1],\n",
      " |              [2, 3]],\n",
      " |             [[4, 5],\n",
      " |              [6, 7]]])\n",
      " |      >>> np.add.reduce(X, 0)\n",
      " |      array([[ 4,  6],\n",
      " |             [ 8, 10]])\n",
      " |      >>> np.add.reduce(X) # confirm: default axis value is 0\n",
      " |      array([[ 4,  6],\n",
      " |             [ 8, 10]])\n",
      " |      >>> np.add.reduce(X, 1)\n",
      " |      array([[ 2,  4],\n",
      " |             [10, 12]])\n",
      " |      >>> np.add.reduce(X, 2)\n",
      " |      array([[ 1,  5],\n",
      " |             [ 9, 13]])\n",
      " |      \n",
      " |      You can use the ``initial`` keyword argument to initialize the reduction\n",
      " |      with a different value, and ``where`` to select specific elements to include:\n",
      " |      \n",
      " |      >>> np.add.reduce([10], initial=5)\n",
      " |      15\n",
      " |      >>> np.add.reduce(np.ones((2, 2, 2)), axis=(0, 2), initial=10)\n",
      " |      array([14., 14.])\n",
      " |      >>> a = np.array([10., np.nan, 10])\n",
      " |      >>> np.add.reduce(a, where=~np.isnan(a))\n",
      " |      20.0\n",
      " |      \n",
      " |      Allows reductions of empty arrays where they would normally fail, i.e.\n",
      " |      for ufuncs without an identity.\n",
      " |      \n",
      " |      >>> np.minimum.reduce([], initial=np.inf)\n",
      " |      inf\n",
      " |      >>> np.minimum.reduce([[1., 2.], [3., 4.]], initial=10., where=[True, False])\n",
      " |      array([ 1., 10.])\n",
      " |      >>> np.minimum.reduce([])\n",
      " |      Traceback (most recent call last):\n",
      " |          ...\n",
      " |      ValueError: zero-size array to reduction operation minimum which has no identity\n",
      " |  \n",
      " |  reduceat(...)\n",
      " |      reduceat(array, indices, axis=0, dtype=None, out=None)\n",
      " |      \n",
      " |      Performs a (local) reduce with specified slices over a single axis.\n",
      " |      \n",
      " |      For i in ``range(len(indices))``, `reduceat` computes\n",
      " |      ``ufunc.reduce(array[indices[i]:indices[i+1]])``, which becomes the i-th\n",
      " |      generalized \"row\" parallel to `axis` in the final result (i.e., in a\n",
      " |      2-D array, for example, if `axis = 0`, it becomes the i-th row, but if\n",
      " |      `axis = 1`, it becomes the i-th column).  There are three exceptions to this:\n",
      " |      \n",
      " |      * when ``i = len(indices) - 1`` (so for the last index),\n",
      " |        ``indices[i+1] = array.shape[axis]``.\n",
      " |      * if ``indices[i] >= indices[i + 1]``, the i-th generalized \"row\" is\n",
      " |        simply ``array[indices[i]]``.\n",
      " |      * if ``indices[i] >= len(array)`` or ``indices[i] < 0``, an error is raised.\n",
      " |      \n",
      " |      The shape of the output depends on the size of `indices`, and may be\n",
      " |      larger than `array` (this happens if ``len(indices) > array.shape[axis]``).\n",
      " |      \n",
      " |      Parameters\n",
      " |      ----------\n",
      " |      array : array_like\n",
      " |          The array to act on.\n",
      " |      indices : array_like\n",
      " |          Paired indices, comma separated (not colon), specifying slices to\n",
      " |          reduce.\n",
      " |      axis : int, optional\n",
      " |          The axis along which to apply the reduceat.\n",
      " |      dtype : data-type code, optional\n",
      " |          The type used to represent the intermediate results. Defaults\n",
      " |          to the data type of the output array if this is provided, or\n",
      " |          the data type of the input array if no output array is provided.\n",
      " |      out : ndarray, None, or tuple of ndarray and None, optional\n",
      " |          A location into which the result is stored. If not provided or None,\n",
      " |          a freshly-allocated array is returned. For consistency with\n",
      " |          ``ufunc.__call__``, if given as a keyword, this may be wrapped in a\n",
      " |          1-element tuple.\n",
      " |      \n",
      " |          .. versionchanged:: 1.13.0\n",
      " |             Tuples are allowed for keyword argument.\n",
      " |      \n",
      " |      Returns\n",
      " |      -------\n",
      " |      r : ndarray\n",
      " |          The reduced values. If `out` was supplied, `r` is a reference to\n",
      " |          `out`.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      A descriptive example:\n",
      " |      \n",
      " |      If `array` is 1-D, the function `ufunc.accumulate(array)` is the same as\n",
      " |      ``ufunc.reduceat(array, indices)[::2]`` where `indices` is\n",
      " |      ``range(len(array) - 1)`` with a zero placed\n",
      " |      in every other element:\n",
      " |      ``indices = zeros(2 * len(array) - 1)``,\n",
      " |      ``indices[1::2] = range(1, len(array))``.\n",
      " |      \n",
      " |      Don't be fooled by this attribute's name: `reduceat(array)` is not\n",
      " |      necessarily smaller than `array`.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      To take the running sum of four successive values:\n",
      " |      \n",
      " |      >>> np.add.reduceat(np.arange(8),[0,4, 1,5, 2,6, 3,7])[::2]\n",
      " |      array([ 6, 10, 14, 18])\n",
      " |      \n",
      " |      A 2-D example:\n",
      " |      \n",
      " |      >>> x = np.linspace(0, 15, 16).reshape(4,4)\n",
      " |      >>> x\n",
      " |      array([[ 0.,   1.,   2.,   3.],\n",
      " |             [ 4.,   5.,   6.,   7.],\n",
      " |             [ 8.,   9.,  10.,  11.],\n",
      " |             [12.,  13.,  14.,  15.]])\n",
      " |      \n",
      " |      ::\n",
      " |      \n",
      " |       # reduce such that the result has the following five rows:\n",
      " |       # [row1 + row2 + row3]\n",
      " |       # [row4]\n",
      " |       # [row2]\n",
      " |       # [row3]\n",
      " |       # [row1 + row2 + row3 + row4]\n",
      " |      \n",
      " |      >>> np.add.reduceat(x, [0, 3, 1, 2, 0])\n",
      " |      array([[12.,  15.,  18.,  21.],\n",
      " |             [12.,  13.,  14.,  15.],\n",
      " |             [ 4.,   5.,   6.,   7.],\n",
      " |             [ 8.,   9.,  10.,  11.],\n",
      " |             [24.,  28.,  32.,  36.]])\n",
      " |      \n",
      " |      ::\n",
      " |      \n",
      " |       # reduce such that result has the following two columns:\n",
      " |       # [col1 * col2 * col3, col4]\n",
      " |      \n",
      " |      >>> np.multiply.reduceat(x, [0, 3], 1)\n",
      " |      array([[   0.,     3.],\n",
      " |             [ 120.,     7.],\n",
      " |             [ 720.,    11.],\n",
      " |             [2184.,    15.]])\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data descriptors defined here:\n",
      " |  \n",
      " |  identity\n",
      " |      The identity value.\n",
      " |      \n",
      " |      Data attribute containing the identity element for the ufunc, if it has one.\n",
      " |      If it does not, the attribute value is None.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> np.add.identity\n",
      " |      0\n",
      " |      >>> np.multiply.identity\n",
      " |      1\n",
      " |      >>> np.power.identity\n",
      " |      1\n",
      " |      >>> print(np.exp.identity)\n",
      " |      None\n",
      " |  \n",
      " |  nargs\n",
      " |      The number of arguments.\n",
      " |      \n",
      " |      Data attribute containing the number of arguments the ufunc takes, including\n",
      " |      optional ones.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      Typically this value will be one more than what you might expect because all\n",
      " |      ufuncs take  the optional \"out\" argument.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> np.add.nargs\n",
      " |      3\n",
      " |      >>> np.multiply.nargs\n",
      " |      3\n",
      " |      >>> np.power.nargs\n",
      " |      3\n",
      " |      >>> np.exp.nargs\n",
      " |      2\n",
      " |  \n",
      " |  nin\n",
      " |      The number of inputs.\n",
      " |      \n",
      " |      Data attribute containing the number of arguments the ufunc treats as input.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> np.add.nin\n",
      " |      2\n",
      " |      >>> np.multiply.nin\n",
      " |      2\n",
      " |      >>> np.power.nin\n",
      " |      2\n",
      " |      >>> np.exp.nin\n",
      " |      1\n",
      " |  \n",
      " |  nout\n",
      " |      The number of outputs.\n",
      " |      \n",
      " |      Data attribute containing the number of arguments the ufunc treats as output.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      Since all ufuncs can take output arguments, this will always be (at least) 1.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> np.add.nout\n",
      " |      1\n",
      " |      >>> np.multiply.nout\n",
      " |      1\n",
      " |      >>> np.power.nout\n",
      " |      1\n",
      " |      >>> np.exp.nout\n",
      " |      1\n",
      " |  \n",
      " |  ntypes\n",
      " |      The number of types.\n",
      " |      \n",
      " |      The number of numerical NumPy types - of which there are 18 total - on which\n",
      " |      the ufunc can operate.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.ufunc.types\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> np.add.ntypes\n",
      " |      18\n",
      " |      >>> np.multiply.ntypes\n",
      " |      18\n",
      " |      >>> np.power.ntypes\n",
      " |      17\n",
      " |      >>> np.exp.ntypes\n",
      " |      7\n",
      " |      >>> np.remainder.ntypes\n",
      " |      14\n",
      " |  \n",
      " |  signature\n",
      " |      Definition of the core elements a generalized ufunc operates on.\n",
      " |      \n",
      " |      The signature determines how the dimensions of each input/output array\n",
      " |      are split into core and loop dimensions:\n",
      " |      \n",
      " |      1. Each dimension in the signature is matched to a dimension of the\n",
      " |         corresponding passed-in array, starting from the end of the shape tuple.\n",
      " |      2. Core dimensions assigned to the same label in the signature must have\n",
      " |         exactly matching sizes, no broadcasting is performed.\n",
      " |      3. The core dimensions are removed from all inputs and the remaining\n",
      " |         dimensions are broadcast together, defining the loop dimensions.\n",
      " |      \n",
      " |      Notes\n",
      " |      -----\n",
      " |      Generalized ufuncs are used internally in many linalg functions, and in\n",
      " |      the testing suite; the examples below are taken from these.\n",
      " |      For ufuncs that operate on scalars, the signature is None, which is\n",
      " |      equivalent to '()' for every argument.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> np.core.umath_tests.matrix_multiply.signature\n",
      " |      '(m,n),(n,p)->(m,p)'\n",
      " |      >>> np.linalg._umath_linalg.det.signature\n",
      " |      '(m,m)->()'\n",
      " |      >>> np.add.signature is None\n",
      " |      True  # equivalent to '(),()->()'\n",
      " |  \n",
      " |  types\n",
      " |      Returns a list with types grouped input->output.\n",
      " |      \n",
      " |      Data attribute listing the data-type \"Domain-Range\" groupings the ufunc can\n",
      " |      deliver. The data-types are given using the character codes.\n",
      " |      \n",
      " |      See Also\n",
      " |      --------\n",
      " |      numpy.ufunc.ntypes\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> np.add.types\n",
      " |      ['??->?', 'bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l',\n",
      " |      'LL->L', 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D',\n",
      " |      'GG->G', 'OO->O']\n",
      " |      \n",
      " |      >>> np.multiply.types\n",
      " |      ['??->?', 'bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l',\n",
      " |      'LL->L', 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D',\n",
      " |      'GG->G', 'OO->O']\n",
      " |      \n",
      " |      >>> np.power.types\n",
      " |      ['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', 'LL->L',\n",
      " |      'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D', 'GG->G',\n",
      " |      'OO->O']\n",
      " |      \n",
      " |      >>> np.exp.types\n",
      " |      ['f->f', 'd->d', 'g->g', 'F->F', 'D->D', 'G->G', 'O->O']\n",
      " |      \n",
      " |      >>> np.remainder.types\n",
      " |      ['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', 'LL->L',\n",
      " |      'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'OO->O']\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.sqrt)"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Raw Cell Format",
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
